package org.mcjug.locationmailer.activity;

import org.mcjug.locationmailer.R;
import org.mcjug.locationmailer.util.EmailUtil;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

public class ExceptionDialog extends Dialog {
	
	public ExceptionDialog(Context context, final String exceptionMsg) {
		super(context);
		
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.exception_dialog);

		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.exception_dialog_title);

		EditText text = (EditText) findViewById(R.id.exceptionMsg);
		text.setText(exceptionMsg);
		
		Button sendButton = (Button) findViewById(R.id.sendException);
		sendButton.setOnClickListener(new android.view.View.OnClickListener() {
			public void onClick(View view) {
				try {
					EmailUtil.sendExceptionEmailIntent(exceptionMsg, getContext());
				} catch (Throwable e) {
				}
				ExceptionDialog.this.dismiss();
		    }
		});
		
		Button sendGmailButton = (Button) findViewById(R.id.sendExceptionGmail);
		sendGmailButton.setOnClickListener(new android.view.View.OnClickListener() {
			public void onClick(View view) {
				try {
					EmailUtil.sendExceptionEmail(exceptionMsg, getContext());
				} catch (Throwable e) {
				}
				ExceptionDialog.this.dismiss();
		    }
		});
		
		Button cancelEmailButton = (Button) findViewById(R.id.cancelSendException);
		cancelEmailButton.setOnClickListener(new android.view.View.OnClickListener() {
			public void onClick(View view) {
				ExceptionDialog.this.dismiss();
		    }
		});

	}
}
